package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.TestConstant;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.viewmodel.entity.EntityUserInfo;

import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * CREATE BY zlzxm ON 4/9/21
 */
public class VMMine extends ViewModel {

    private MutableLiveData<EntityUserInfo> liveUser = new MutableLiveData<>();


    public MutableLiveData<EntityUserInfo> getLiveUser() {
        return liveUser;
    }


    public void requestUser(){

        Observable.timer(3, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                        liveUser.setValue(createTestUser());

                    }
                });


    }





    //<editor-fold defaultState="collapsed" desc="测试数据">

    private EntityUserInfo createTestUser(){

        EntityUserInfo entityUserInfo = new EntityUserInfo();

        entityUserInfo.setFaceUlr(TestConstant.PIC_FOUR);
        entityUserInfo.setPhone("1575850252");
        entityUserInfo.setName("欧欧豆豆");
        entityUserInfo.setVipInfo("会员有效期至：2021-10-10 22:00");

        return  entityUserInfo;
    }


    // </editor-fold>

}
